package com.example.customviewtouch.test

import com.example.customviewtouch.downfresh.interfaces.RefreshHeaderState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import java.lang.ref.ReferenceQueue
import java.lang.ref.WeakReference

class Coffee(val tease:String,val price:Double) {
    //初始化代码块
    init {
        println(tease)
        println(price)
        println("init1")
        println(tease)
        println(price)
    }
    init {
        println("init2")
    }
    //次构造函数
    constructor(tease:String) : this("bad",15.8){
        println("constructor")
    }
    //伴生对象
    companion object {

        val flag = false

        fun plus(num1:Int,num2:Int):Int {
            return num1+num2
        }

        init {
            println("companion object init1")
        }
        init {
            println("companion object init2")
        }
    }
}
//主方法验证
fun main(args:Array<String>){
    val coffe = Coffee("e") //用于验证
    /**
     * 验证结果：先后排序
     * companion object init1
     * companion object init2
     * init1
     * init2
     * constructor
     * 总结：伴生对象 > 初始化代码块 > 构造函数 （先>后）
     */
//    val coffee = Coffee("good",9.9) //正常对象创建
////    println(Coffee.flag)  //用于验证伴生对象调用
////    println(Coffee.plus(1,1)) //用于验证伴生对象调用
//
//    val scope = CoroutineScope(Dispatchers.Main)
//    val job = scope.launch {
//
//    }
//    scope.cancel()
//    job.cancel()
    println(RefreshHeaderState.STATE_REFRESHING.ordinal)
    println(RefreshHeaderState.STATE_NORMAL.ordinal)
}
